package com.example.demo001.mapper;

import com.example.demo001.pojo.dto.UserDto;
import com.example.demo001.pojo.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;

@Mapper
public interface UserMapper {



    /**
     * 注册用户
     */
    @Insert("insert into user(username,password,email,create_time,update_time,status) " +
            "values(#{username},#{password},#{email},#{createTime},#{updateTime},#{status})")
    void register(User user);

    @Select("select id from user where username=#{username} and password=#{password}")
    Integer login(UserDto userDto);

    @Select("select id,username,password,status from user where username=#{username}")
    User selectByUsername(String username);

    @Update("update user set status=#{i} where id=#{id}")
    void updateStatus(Integer id, int i);

    @Update("update user set password=#{newPassword}, update_time = #{updateTime} where username=#{current} ")
    void updatePassword(String current, String newPassword, LocalDateTime updateTime);

    @Update("update user set email=#{email}, update_time = #{updateTime} where username=#{username} ")
    void updateEmail(String username, String email,LocalDateTime updateTime);

    @Select("select email,username from user where username=#{username}")
    User selectMailByUsername(String username);

    @Select("select id from user where email=#{email}")
    Integer selectByEmail(String email);

    @Select("select id from user where username=#{username}")
    Integer findName(String username);

    @Select("select id from user where email=#{email}")
    Integer findEmail(String email);

    @Update("update user set password=#{newPassword}, update_time = #{updateTime}, status=#{userStatusNormal} where username=#{username} ")
    void resetPassword(String username, String newPassword, LocalDateTime updateTime, int userStatusNormal);
}
